package com.ruoyi.web.controller.qsng;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qsng.domain.KInvoice;
import com.ruoyi.qsng.service.IKInvoiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发票管理Controller
 * 
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/invoice")
@Api(tags = "pc--发票管理Controller")
public class KInvoiceController extends BaseController
{
    @Autowired
    private IKInvoiceService kInvoiceService;

    /**
     * 查询发票管理列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:invoice:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询发票管理列表")
    public TableDataInfo list(KInvoice kInvoice)
    {
        startPage();
        List<KInvoice> list = kInvoiceService.selectKInvoiceList(kInvoice);
        return getDataTable(list);
    }

    /**
     * 导出发票管理列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:invoice:export')")
    @Log(title = "发票管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出发票管理列表")
    public void export(HttpServletResponse response, KInvoice kInvoice)
    {
        List<KInvoice> list = kInvoiceService.selectKInvoiceList(kInvoice);
        ExcelUtil<KInvoice> util = new ExcelUtil<KInvoice>(KInvoice.class);
        util.exportExcel(response, list, "发票管理数据");
    }

    /**
     * 获取发票管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:invoice:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取发票管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(kInvoiceService.selectKInvoiceById(id));
    }

    /**
     * 新增发票管理
     */
    @PreAuthorize("@ss.hasPermi('qsng:invoice:add')")
    @Log(title = "发票管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增发票管理")
    public AjaxResult add(@RequestBody KInvoice kInvoice)
    {
        return toAjax(kInvoiceService.insertKInvoice(kInvoice));
    }

    /**
     * 修改发票管理
     */
    @PreAuthorize("@ss.hasPermi('qsng:invoice:edit')")
    @Log(title = "发票管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改发票管理")
    public AjaxResult edit(@RequestBody KInvoice kInvoice)
    {
        return toAjax(kInvoiceService.updateKInvoice(kInvoice));
    }

    /**
     * 删除发票管理
     */
    @PreAuthorize("@ss.hasPermi('qsng:invoice:remove')")
    @Log(title = "发票管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value = "删除发票管理")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(kInvoiceService.deleteKInvoiceByIds(ids));
    }
}
